<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/29 0029
 * Time: 上午 9:18
 */

namespace app\sports_admin\service;

use app\exception\BannerException;
use app\sports_admin\model\Banner as BannerModel;
class Banner extends Base
{
    /**
     * 修改排序字段
     */
    public static function updateSort()
    {
        //获取参数
        $params = self::getHttpRequestPrograms();
        $params = $params->param();
        $bool = (new BannerModel())->save(['sort'=>$params['sort']],['id'=>$params['id']]);
        if(!$bool){
            throw new BannerException(['msg'=>'修改失败','errorCode'=>400]);
        }
        return json(['msg'=>'修改成功','code'=>200]);
    }
    /**
     * 修改导航图片
     */
    public static function updateImage()
    {
        //获取参数
        $params = self::getHttpRequestPrograms();
        $params = $params->param();
        $bool = (new BannerModel())->save(['photo'=>$params['img']],['id'=>$params['id']]);
        if(!$bool){
            throw new BannerException(['msg'=>'修改失败','errorCode'=>400]);
        }
        return json(['msg'=>'修改成功','code'=>200]);
    }
}